<#import "/WEB-INF/freemarker_macro/ckeditor.ftl" as editor> 
<#import "/WEB-INF/freemarker_macro/image_upload.ftl" as upload>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<title>添加产品</title>
<link rel="stylesheet" type="text/css" href="${base}/css/admin/global.css" />
<link rel="stylesheet" type="text/css" href="${base}/css/admin/mainframe.css" />
<link rel="stylesheet" type="text/css" href="${base}/css/admin/upload.css" />
<style type="text/css">
.dynamic {
	border: #FF0000 1px solid;
	background-color: red
}

.uploadImg {
	font-size: 12px;
	overflow: hidden;
	position: absolute
}

.file {
	position: absolute;
	z-index: 100;
	margin-left: -180px;
	font-size: 60px;
	opacity: 0;
	filter: alpha(opacity = 0);
	margin-top: -5px;
}
</style>

<link rel="stylesheet" type="text/css" href="${base}/js/ymPrompt/style/bluebar/ymPrompt.css" />
<script type="text/javascript" src="${base}/js/jquery-1.4.2.min.js"></script>
<script type='text/javascript' src="${base}/js/ymPrompt/ymPrompt.js"></script>
<script type='text/javascript' src="${base}/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="${base}/js/jquery.blockUI.js"></script>

<script type="text/javascript">

function getPreviewpro(obj){
	if(obj){
		if(window.navigator.userAgent.indexOf("Firefox")>=1){
			if(obj.files){
				var t=obj.files.item(0).getAsDataURL();
				var m=jQuery(obj).parents("dl").children("dd");
				m.children("img").attr("src",t);
				jQuery(obj).parents("dl").children("dt").children(".delin").val(0);
			}
			return;
		}
		
		var t=obj.value;
		var m=jQuery(obj).parents("dl").children("dd");
		m.children("img").attr("src",t);
		jQuery(obj).parents("dl").children("dt").children(".delin").val(0);
	}
}

function checkForm(){
	  	
  	if($.trim($("#prodName").val()) == ""){
  		alert("请填写产品名称!");
  		return false;
  	}
  	if($.trim($("#typeId").val()) == ""){
  		alert("请选择产品分类!");
  		return false;
  	}
  	if($.trim($("#prodCode").val()) == ""){
  		alert("请选择产品编码!");
  		return false;
  	}
  	
  	var hasImg = false;
	for(var i=0;i<Upload.refImgs.length;i++){
		if(Upload.refImgs[i]&&$.trim(Upload.refImgs[i])!=""){
			hasImg = true;
			break;
		}
	}
	if(!hasImg){
		_alert("请上传图片!");
		return;
	}else{
		var imgs = [];
		for(var i=0;i<Upload.refImgs.length;i++){
			if(Upload.refImgs[i]&&$.trim(Upload.refImgs[i])!=""){
				imgs.push(Upload.refImgs[i]);
			}
		}
		if(imgs[0]){
			$("#picture").val(imgs[0]);
		}
		if(imgs[1]){
			$("#pic2").val(imgs[2]);
		}
		if(imgs[2]){
			$("#pic3").val(imgs[3]);
		}
		if(imgs[3]){
			$("#pic4").val(imgs[4]);
		}
		if(imgs[4]){
			$("#pic5").val(imgs[5]);
		}
	}
  	return true;
}
  
function saveForm(type){
  	if(!checkForm()){
  		return false;
  	}
  	
  	$("#form1").submit();
}

//图片上传
Upload = {
	imgServer : "${base}",
	refImgs : [],
	
	getImgSrc : function(flag,src,uploadNum){
		if(flag==1 || flag==2){
			ymPrompt.errorInfo({message:'文件太大，最大只允许1M'});
			return;
		}
		if(flag==3){
			ymPrompt.errorInfo({message:'应用程序错误!'});
			return;
		}
		if(src!="" && src!=null){
			$("#uploadFile_span"+uploadNum).html("");
			$("#uploadFile_span"+uploadNum).append('<img width=100% height=100% src="'+Upload.imgServer+src+'_M.jpg" />');
			Upload.refImgs[uploadNum] = src;
		}
	}
};

</script>
</head>
<body> 
<@upload.imgUpload action="${base}/admin/prod/uploadImg.do" />
<form id="form1" name="form1" action="${base}/admin/prod/save.do" method="post">
<div class="mbody">
	<div class="tagLine">
		<a href="${base}/admin/main.do" target="_self">桌面</a> &gt;&gt; 产品管理 &gt;&gt; 添加产品
	</div>
	<input type="hidden" id="picture" name="product.picture" />
	<input type="hidden" id="pic2" name="product.pic2" />
	<input type="hidden" id="pic3" name="product.pic3" />
	<input type="hidden" id="pic4" name="product.pic4" />
	<input type="hidden" id="pic5" name="product.pic5" />
	<div class="cbody">
		<div class="opeArea">
			<div class="wbox">
				<h5 class="titnav">
					产品基本信息
				</h5>
				<div class="inbox">
					<table border="0" cellpadding="0" cellspacing="0" width="100%"
						class="infotable">
						<tr>
							<td class="titletd">
								商品名称:
								<span class="import">*</span>
							</td>
							<td class="infotd" colspan="5">
								<input id="prodName" name="product.prodName" type="text"
									class="txts infotext" style="width: 80%" value=""
									maxlength="60" />
								<span>限定在30个汉字内(60个字符)</span>
							</td>
						</tr>
						<tr>
							<td class="titletd">
								产品分类:
								<span class="import">*</span>
							</td>
							<td class="infotd" colspan="5">
								<select id="typeId" name="product.prodType.typeId">
									<option>请选择</option>
									<#if types?? && types?size gt 0>
										<#list types as type>
											<option value="${type.typeId}">${type.typeName}</option>
										</#list>
									</#if>
								</select>
							</td>
						</tr>
						<tr>
							<td class="titletd">
								产品编码:
								<span class="import">*</span>
							</td>
							<td class="infotd">
								<input id="prodCode" name="product.prodCode" type="text"
									class="txts infotext" value="" onblur="" maxlength="32" />
								(唯一)
							</td>
						</tr>
						<tr>
							<td class="titletd">
								是否上架:
							</td>
							<td class="infotd" colspan="5">
								<input id="status1" name="product.status" type="radio"
									value="1" />
								<label for="status1">
									是
								</label>
								<input id="status2" name="product.status" type="radio"
									value="2" checked />
								<label for="status2">
									否
								</label>
							</td>
						</tr>
						<tr>
							<td class="titletd">
								所属语种:
								<span class="import">*</span>
							</td>
							<td class="infotd" colspan="5">
								<select name="product.language">
	                			<#if languages?? && languages?size gt 0>
	                				<#list languages?keys as key>
	                					<option value="${key}">${languages[key]}</option>
	                				</#list>
	                			</#if>
	                		</select>
							</td>
						</tr>
						<tr>
							<td class="titletd">
								产品图片
								<span class="import">*</span>
							</td>
							<td class="infotd" colspan="5">
								<div>
									<label class="label">
										产品 图片：
									</label>
									<span>
										<div style="position: absolute; left: 400px; color: rgb(255, 102, 0); font-size: 12px;">
										上传1200px*1200px以上的图片，即可在产品详情页面提供图片放大功能
										</div> <!-- imageUpload -->
										<div data-firstrun="1" id="J_UploadPicTab"
											class="upload-manager upload-pic">
											<ul class="tabs">
												<li class="selected">
													<span><a href="javascript:;" title="">上传新图片</a>
													</span>
												</li>
											</ul>
											<div style="display: block;" class="panel panel-local">
												<div class="pic-manager">
													<div class="side">
														<div></div>
														<ul>
															<li class="s1">
																<a href="javascript:;">d1</a>
															</li>
															<li class="s2">
																<a href="javascript:;">d2</a>
															</li>
															<li class="s3">
																<a href="javascript:;">d3</a>
															</li>
															<li class="s4">
																<a href="javascript:;">d4</a>
															</li>
															<li class="s5">
																<a href="javascript:;">d5</a>
															</li>
														</ul>
													</div>
													<div class="main">
														<input value="_fma.pu._0.ima" class="J_FirstPicField" type="hidden">
														<ul id="J_PanelLocalList">
															<li class="first">
																<input class="J_PicUrl" name="picUrl1" value="" type="hidden">
																<input name="image_pos" value="1" type="hidden">
																<span class="preview" id="uploadFile_span1"></span>
																<span class="upload">
																	<a href="javascript:;">
																		<span id="ufc1">
																			<input id="uploadFile1" name="_fma.pu._0.ima" 
																				type="file" onchange="upload(1)" />
																		</span>
																	</a>
																</span>
															</li>
															<li class="loading">
																<input class="J_PicUrl" name="picUrl2" value="" type="hidden">
																<input name="image_pos" value="2" type="hidden">
																<span class="preview" id="uploadFile_span2"></span>
																<span class="upload">
																	<a href="javascript:;">
																		<span id="ufc2">
																			<input id="uploadFile2" name="_fma.pu._0.imag" 
																				type="file" onchange="upload(2)" />
																		</span>
																	</a>
																</span>
															</li>
															<li class="">
																<input class="J_PicUrl" name="picUrl3" value="" type="hidden">
																<input name="image_pos" value="3" type="hidden">
																<span class="preview" id="uploadFile_span3"></span>
																<span class="upload">
																	<a href="javascript:;">
																		<span id="ufc3">
																			<input id="uploadFile3" name="_fma.pu._0.image" 
																				type="file" onchange="upload(3)" />
																		</span>
																	</a>
																</span>
															</li>
															<li class="">
																<input class="J_PicUrl" name="picUrl4" value="" type="hidden">
																<input name="image_pos" value="4" type="hidden">
																<span class="preview" id="uploadFile_span4"></span>
																<span class="upload">
																	<a href="javascript:;">
																		<span id="ufc4">
																			<input id="uploadFile4" name="_fma.pu._0.image4" 
																				type="file" onchange="upload(4)" />
																		</span>
																	</a>
																</span>
															</li>
															<li class="last">
																<input class="J_PicUrl" name="picUrl5" value="" type="hidden">
																<input name="image_pos" value="5" type="hidden">
																<span class="preview" id="uploadFile_span5"></span>
																<span class="upload">
																	<a href="javascript:;">
																		<span id="ufc5">
																			<input id="uploadFile5" name="_fma.pu._0.image5" 
																				type="file" onchange="upload(5)" />
																		</span>
																	</a>
																</span>
															</li>
														</ul>
													</div>
												</div>
												<br>
												<div class="msg">
													<span class="tips">
														图片至少上传1张（第1张不计图片空间容量），图片大小不能超过500K </span>
												</div>
											</div>
										</div> 
									</span>
								</div>
							</td>
						</tr>
					</table>
				</div>

				<div class="wbox">
					<h5 class="titnav">
						商品简介:
					</h5>
					<div class="inbox">
						<textarea id="shortDes" name="product.shortDesc" class="info"
							style="width: 60%; height: 100px;"></textarea>
						(限定在512个汉字内(1024个字符))
					</div>

					<h5 class="titnav">
						详细介绍
					</h5>
					<div class="inbox">
						<@editor.ckeditor id="prodDesc" name="product.prodDesc" config="full"
							class="textsbox" height="550" width="1210"/>
					</div>
				</div>
			</div>
		</div>
		<div class="bottomSaveline">
			<button class="sysSaveBtn" onclick="return saveForm();" type="button">
				<b class="icon icon_savetolist"></b>保存并返回商品列表
			</button>
		</div>
	</div>
</div>
</form>
<iframe name="ajax" style="display: none;"></iframe>
</body>
</html>